'use strict';

/**
 * @ngdoc function
 * @name appApp.controller:ProfessionSpaceCtrl
 * @description
 * # ProfessionSpaceCtrl
 * Controller of the appApp
 */
angular.module('appApp')
  .controller('ProfessionSpaceCtrl', function ($scope,onlineFac) {
    $scope.currentPage = 1;
	  //设置每页数量
	  $scope.perPage = 5;

	  $scope.getArticles = function(){
	  	$scope.article_list = null;
	  	onlineFac.article.articles({
	      category_id: $scope.current_category,
	      page: $scope.currentPage
	    },function(data){
	      $scope.article_list = data.info;
	      $scope.totalItems = data.total;
	    },function(data){
	      alert(data.data.info);
	    });
	  }

	  $scope.getCategoty = function(){
	  	onlineFac.article.categorylist({
	      listId:46
	    },function(data){
	      $scope.express_list = data.info;
	      if($scope.express_list){
	      	$scope.express_list[0]['choose'] = true;
	      	$scope.current_category = $scope.express_list[0]['children'][0]['id'];
	      	$scope.getArticles();
	      }
	    },function(data){
	      alert(data.data.info);
	    });
	  }

	  $scope.firstLevel = function(menu){
	  	menu.choose = !menu.choose;
	  	if(!menu.children){
	  		$scope.current_category = menu.id;
	  		$scope.currentPage = 1;
	  		$scope.getArticles();
	  	}
	  	

	  }

	  $scope.secondLevel = function(id){
			$scope.current_category = id;
	  	$scope.currentPage = 1;
	  	$scope.getArticles();
	  }
  });
